/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

ZlangInvokeFunction ZlangInvokeFunction_guilabel_Create_guiwindow;
int ZlangInvokeFunction_guilabel_Create_guiwindow( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guilabel_common = & (guilabel_direct_prop->common) ;

	EVAL_GTK_WIDGET_NEW_IN_CREATE( guilabel_common->gtk_widget , gtk_label_new(NULL) )
	SET_CONTROL_DEFAULT_STYLE( in1 , guilabel_common->gtk_widget )

	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guilabel_common->guiwindow_obj , in1 )

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_Create_guiwindow_string;
int ZlangInvokeFunction_guilabel_Create_guiwindow_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*str = NULL ;
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guilabel_common = & (guilabel_direct_prop->common) ;

	CallRuntimeFunction_string_GetStringValue( rt , in2 , & str , NULL );

	EVAL_GTK_WIDGET_NEW_IN_CREATE( guilabel_common->gtk_widget , gtk_label_new_with_mnemonic(str) )
	SET_CONTROL_DEFAULT_STYLE( in1 , guilabel_common->gtk_widget )

	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guilabel_common->guiwindow_obj , in1 )

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_Create_guiwindow_string_int;
int ZlangInvokeFunction_guilabel_Create_guiwindow_string_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*str = NULL ;
	int						justify ;
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(out1) ;
	struct ZlangDirectProperty_guiwidget_common	*guilabel_common = & (guilabel_direct_prop->common) ;

	CallRuntimeFunction_string_GetStringValue( rt , in2 , & str , NULL );
	CallRuntimeFunction_int_GetIntValue( rt , in3 , & justify );

	EVAL_GTK_WIDGET_NEW_IN_CREATE( guilabel_common->gtk_widget , gtk_label_new_with_mnemonic(str) )
	SET_CONTROL_DEFAULT_STYLE( in1 , guilabel_common->gtk_widget )

	gtk_label_set_justify( GTK_LABEL(guilabel_common->gtk_widget) , justify );

	TRANSFER_INPUT_OBJECT_TO_NEW_OBJECT( guilabel_common->guiwindow_obj , in1 )

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_SetLabel_string;
int ZlangInvokeFunction_guilabel_SetLabel_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*str = NULL ;
	char						*p_str = NULL ;
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(obj) ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & str , NULL );

	p_str = g_strdup( str ) ;
	gtk_label_set_text( GTK_LABEL(guilabel_direct_prop->common.gtk_widget) , p_str );
	g_object_set_data_full( G_OBJECT(guilabel_direct_prop->common.gtk_widget) , "label-text" , p_str , g_free );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_SetMarkupLabel_string;
int ZlangInvokeFunction_guilabel_SetMarkupLabel_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*str = NULL ;
	char						*p_str = NULL ;
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(obj) ;

	CallRuntimeFunction_string_GetStringValue( rt , in1 , & str , NULL );

	p_str = g_strdup( str ) ;
	gtk_label_set_markup( GTK_LABEL(guilabel_direct_prop->common.gtk_widget) , p_str );
	g_object_set_data_full( G_OBJECT(guilabel_direct_prop->common.gtk_widget) , "markup-label-text" , p_str , g_free );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_SetJustify_int;
int ZlangInvokeFunction_guilabel_SetJustify_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int						justify ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & justify );

	gtk_label_set_justify( GTK_LABEL(guilabel_direct_prop->common.gtk_widget) , justify );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_SetWidthChars_int;
int ZlangInvokeFunction_guilabel_SetWidthChars_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						n_chars ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & n_chars );

	gtk_label_set_width_chars( GTK_LABEL(guilabel_direct_prop->common.gtk_widget) , n_chars );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_SetMaxWidthChars_int;
int ZlangInvokeFunction_guilabel_SetMaxWidthChars_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	int32_t						n_chars ;

	CallRuntimeFunction_int_GetIntValue( rt , in1 , & n_chars );

	gtk_label_set_max_width_chars( GTK_LABEL(guilabel_direct_prop->common.gtk_widget) , n_chars );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guilabel_SetSelectable_bool;
int ZlangInvokeFunction_guilabel_SetSelectable_bool( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	unsigned char					is_selectable ;

	CallRuntimeFunction_bool_GetBoolValue( rt , in1 , & is_selectable );

	gtk_label_set_selectable( GTK_LABEL(guilabel_direct_prop->common.gtk_widget) , is_selectable );

	TRANSFER_MASTER_OBJECT_TO_OUTPUT_OBJECT

	return 0;
}

ZLANG_INVOKE_FUNCTION_guiwidget_all_common_functions( label )

ZLANG_INVOKE_FUNCTION_guictl_all_common_functions( label )

ZlangInvokeFunction ZlangInvokeFunction_guilabel_GetLabel;
int ZlangInvokeFunction_guilabel_GetLabel( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guilabel		*guilabel_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	char						*str = NULL ;

	str = (char*)gtk_label_get_label( GTK_LABEL(guilabel_direct_prop->common.gtk_widget) );

	CallRuntimeFunction_string_SetStringValue( rt , out1 , str , STRLEN_OF_STRING );

	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guilabel;
void *ZlangCreateDirectProperty_guilabel( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guilabel		*guilabel_prop = NULL ;
	struct ZlangDirectProperty_guiwidget_common	*guilabel_common = NULL ;
	
	guilabel_prop = (struct ZlangDirectProperty_guilabel *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guilabel) ) ;
	if( guilabel_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guilabel_prop , 0x00 , sizeof(struct ZlangDirectProperty_guilabel) );

	guilabel_common = (struct ZlangDirectProperty_guiwidget_common *)guilabel_prop ;
	guilabel_common->gtk_widget_type_id = GTK_TYPE_LABEL ;

	INIT_ZLANGDIRECTPROPERTY_guiwidget_common(guilabel)
	
	return guilabel_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guilabel;
void ZlangDestroyDirectProperty_guilabel( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guilabel	*guilabel_direct_prop = GetObjectDirectProperty(obj) ;
	
	CLEAN_ZLANGDIRECTPROPERTY_guiwidget_common(guilabel)

	ZLFREE( guilabel_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guilabel;
void ZlangSummarizeDirectPropertySize_guilabel( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guilabel) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guilabel =
	{
		ZLANG_OBJECT_guilabel , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guilabel , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guilabel , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guilabel , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guilabel;
struct ZlangObject *ZlangImportObject_guilabel( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangObject	*prop = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guilabel , & direct_funcs_guilabel , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	prop = AddPropertyInObject( rt , obj , GetFloatObjectInRuntimeObjectsHeap(rt) , "ALIGN_LEFT" ) ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_float_SetFloatValue( rt , prop , 0.0 );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetFloatObjectInRuntimeObjectsHeap(rt) , "ALIGN_CENTER" ) ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_float_SetFloatValue( rt , prop , 0.5 );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetFloatObjectInRuntimeObjectsHeap(rt) , "ALIGN_RIGHT" ) ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_float_SetFloatValue( rt , prop , 1.0 );
	SetConstantObject( prop );
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_Create_guiwindow , ZLANG_OBJECT_guilabel , "Create" , ZLANG_OBJECT_guiwindow,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_Create_guiwindow_string , ZLANG_OBJECT_guilabel , "Create" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_Create_guiwindow_string_int , ZLANG_OBJECT_guilabel , "Create" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_SetLabel_string , ZLANG_OBJECT_guilabel , "SetLabel" , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_SetMarkupLabel_string , ZLANG_OBJECT_guilabel , "SetMarkupLabel" , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_SetJustify_int , ZLANG_OBJECT_guilabel , "SetJustify" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_SetWidthChars_int , ZLANG_OBJECT_guilabel , "SetWidthChars" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_SetMaxWidthChars_int , ZLANG_OBJECT_guilabel , "SetMaxWidthChars" , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_SetSelectable_bool , ZLANG_OBJECT_guilabel , "SetSelectable" , ZLANG_OBJECT_bool,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guiwidget_all_common_functions( label )

	ADD_FUNCTION_AND_PARAMETERS_IN_OBJECT_guictl_all_common_functions( label )

	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guilabel_GetLabel , ZLANG_OBJECT_string , "GetLabel" , NULL ) ;
	if( func == NULL )
		return NULL;
	
	return obj ;
}

